<template>
    <div class="Search_all">
        <van-nav-bar style="position: fixed; width: 100%;" title="搜索详情" left-text="返回" right-text="" left-arrow
        @click-left="onClickLeft" />
        <div class="book_list">
            <ul>
                <li v-for="(item, index) in id" :key="index">
                    <div @click="toread(item,book_names[index],book_bg[index])" class="img_left">
                        <img :src="book_bg[index]" alt="">
                    </div>
                    <div class="img_right">
                        <span class="book_name">{{ book_names[index] }}</span>
                        <button class="look_book_btn" @click="toread(item,book_names[index],book_bg[index])">查看图书</button>
                        <br>
                        <span class="author">{{ author[index] }}</span>
                        <br>
                        <div class="book_article">
                        {{ article[index] }}
                        </div>
                    </div>
                </li>
            </ul>
        </div>        
    </div>
</template>
<style>
</style>
<style lang="less">
@import '../pubilc1/public.less';

.Search_all {
    color: @font_color;
    height: 100vh;
    width: 100vw;
    overflow: scroll;
    .book_list {
        margin-top: 60px;
        margin-bottom: 60px;
        display: block;
        position: relative;
        width: 100vw;
        overflow: hidden;
        ul {
            text-align: left;
            li {
                margin:13px 10px;
                width: 100vw;
                left: 0;
                padding: 0;
                position: relative;
                display: block;
                border-bottom: #ffce6c solid 1px;

                .img_left {
                    display: inline-block;

                    img {
                        object-fit: cover;
                        width: 90px;
                        height: 135px;
                    }
                }

                .img_right {
                    display: inline-block;
                    width: 70vw;
                    margin-left: 10px;
                    color: #000;

                    .look_book_btn {
                        display: inline;
                        position: relative;
                        margin-left: 2vw;
                        line-height: 35px;
                        width: 80px;
                        height: 30px;
                        padding: 0;
                        font-size: 12px;
                        line-height: 12px;
                        border: 0;
                        background-color: rgb(255, 186, 122);
                        border-radius: 5px;
                        top: 0;
                        color: white;
                    }

                    .book_name {
                        line-height: 35px;
                        font-size: 14px;
                        width: 160px;
                        text-overflow: ellipsis;
                        display: inline-flex;
                        position: relative;
                        left: 0;
                        font-weight: bold;
                        overflow: hidden;
                        white-space: nowrap;
                        text-overflow: ellipsis;
                    }

                    .author {
                        display: block;
                        font-size: 12px;
                        width: 80px;
                        color: #9e9e9e;
                        white-space: nowrap;
                        text-overflow: ellipsis;
                    }

                    .book_article {
                        width: 60vw;
                        display: block;
                        height: 36px;
                        overflow: hidden;
                        white-space: nowrap;
                        text-overflow: ellipsis;
                        font-size: 12px;
                        font-family: "黑体";
                        color: #636363;
                    }
                }
            }
        }
    }
}
</style>

<script>
// 导入接口
import { searchList } from "../api/myindex";

export default {
    data() {
        return {
            myarr:[],
            id: [],
            book_names: [],
            book_bg:[],
            author: [],
            article: [],
            searchkey:''
        }
    },
    created() {
        console.log(this.$route.query);
        this.searchkey = this.$route.query.myVlaue;
        // 获取搜索关键字
        this.getmydata2();
    },
    methods: {
        onClickLeft() {
            this.$router.back();
        },
        toread(myid,bookname,mybg) {
            this.$router.push({ path: "/Read" ,query: { 
                id:myid,
                name:bookname,
                bg:mybg
            }});
        },
        async getmydata2() {
            try {
                // 调用接口
                console.log("searchkey",this.searchkey);
                const response = await searchList({
                    key:this.searchkey,
                    page:1
                });
                // 请求成功
                console.log("请求成功！");
                if (response) {
                    console.log(response);
                    response.data.books.map(item => {
                        this.id.push(item.bookId);
                        this.book_names.push(item.title);
                        this.author.push(item.author);
                        this.article.push(item.description.slice(3,-3));
                        this.book_bg.push(item.coverImage);
                    });
                }
            } catch (err) {
                // 请求失败
                console.log("请求失败,请刷新", err);
            }
        }
    }
}

</script>